Repository navigation
Conversation
|
Thanks for taking the time to share this @zhubonan! I would appreciate the first two commits to be sent as standalone PR! Then this PR should be able to contain only new HIP code, which should be easier to review. |
|
@RMeli once you are back from holidays: can we access the AMD GPU through the CSCS CI now? I remember it was not fully available at some point. |
Port the HIP implementation qualified by symmetrix-xl (bonan-group/
symmetrix-xl) to sphericart's core library:
- Compile the existing CUDA-dialect kernels at runtime with hipRTC,
loading libhiprtc dynamically (src/hiprtc_lite.{hpp,cpp}, a port of
symmetrix-xl's jit_hiprtc) and launching through hipModuleLoadData /
hipModuleLaunchKernel (src/hip_base.cpp), targeting the GCN
architecture reported by hipGetDeviceProperties.
- Add sphericart::hip::SphericalHarmonics/SolidHarmonics mirroring the
CUDA classes (src/sphericart_hip.cpp, include/*.hpp), with prefactors
uploaded to the device of the input pointers.
- Guard the warp-shuffle mask in sphericart_impl.cu: hipRTC requires a
64-bit mask where CUDA uses a 32-bit one.
- Wire SPHERICART_ENABLE_HIP in CMake following the SYCL backend
conventions; only ROCm headers and libamdhip64 are needed at build
time (no HIP compiler), mirroring the CUDA backend's gpu-lite
philosophy. HIP is mutually exclusive with CUDA/SYCL builds.
- Add test_derivatives_hip (skips without a device) and a HIP example,
both gated like their SYCL counterparts, plus a ROCm-container CI job
mirroring the SYCL workflow.
Verified on a gfx1151 (Radeon 8060S, ROCm 7.14): l_max 0-14 float/double
gradients, hessians, and backward pass match finite-difference
references; the HIP example matches the CPU calculator to ~1e-15.
Mirror the async-lifecycle CUDA API on the HIP backend so consumers (symmetric workloads like symmetrix-xl's spherical-harmonics evaluation) can drive the same lifecycle on AMD GPUs: - spherical_harmonics_hip_base takes an explicit synchronize flag (default true) and only calls hipStreamSynchronize when set; compute_with_gradients_async enqueues without synchronizing. - release_device_resources frees the lazily allocated prefactors on the bound device; calculators are single-device and reject migration, matching the CUDA calculator semantics. - Adopt the overflow-safe grid rounding from the async-lifecycle work. - test_hip_async: async-vs-sync bit-for-bit parity, enqueue-must-beat- sync timing, and release/realloc transparency (skips without a GPU).
Mirror gpu-lite's actionable diagnostic instead of failing later inside hipModuleLaunchKernel with an opaque invalid-argument error, and widen the CI HIP ctest filter so test_hip_async runs alongside test_derivatives_hip (both skip without a device; example_hip does not skip and stays out of the filter).
- test_hip_async now measures the enqueue burst against a single stream drain with the CUDA test's 4x margin, instead of comparing against a synchronous launch loop, so the mirrored tests assert the same property. - Install git in the HIP CI container alongside cmake and the compilers. - README: the published wheels do not include the HIP backend.
|
Updated the branch as requested: the CUDA 64-bit indexing and CUDA async/resource-lifecycle commits are no longer part of this PR. PR #257 now contains only the HIP backend and its HIP-specific API/tests. I am preparing the two CUDA commits separately and will not open that PR until the branch is ready for confirmation. |
|
@Luthaf yes, CI on the MI300 cluster should now be available. I can have a go at setting it up later today. |
Luthaf
left a comment
There was a problem hiding this comment.
The code looks clean, I have a couple of questions to understand the limitations better!
|
cscs-ci run all |
Summary
This PR adds a HIP (AMD ROCm) backend to the core C++ library.
The previously included CUDA indexing and lifecycle changes have been removed from this branch and will be proposed separately. This PR now changes only HIP-facing build, API, test, example, CI, and documentation surfaces, apart from the small shared-kernel guard required by hipRTC.
HIP backend
SPHERICART_ENABLE_HIP, mutually exclusive with the CUDA and SYCL backends.libhiprtcis loaded dynamically and kernels are launched throughhipModuleLoadData,hipModuleGetFunction, andhipModuleLaunchKernel.libamdhip64at build time; a HIP compiler is not required.sphericart::hip::SphericalHarmonicsandSolidHarmonics, including synchronous compute, gradients, Hessians, backward, opt-in asynchronous gradients, and explicit release of lazily allocated device resources.hipGetDeviceProperties().gcnArchName, caches modules/functions per device, and reports shared-memory requests above the device opt-in limit before launch.Tests and examples
test_derivatives_hip: forward, gradients, Hessians, and backward parity overl_max0-14 for spherical and solid harmonics.test_hip_async: synchronous/asynchronous result parity, enqueue behavior, and release/reallocation transparency.examples/hip/example.cppand a gated CMake target.hip-testsCI job using a ROCm development container. Tests skip cleanly when no AMD GPU is exposed, while still compiling the complete backend.Verification
Verified on ROCm 7.14 with a
gfx1151device:1e-15; float32 is approximately3e-7.Scope
The scope follows the existing SYCL backend: C++ API, build option, tests, example, CI, and documentation. C API, Python, Torch, and JAX HIP exposure are not included. Published wheels do not enable the HIP backend.